ProfileHeader.tsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. "use client";
  2. import { GameListRep, GameRequest } from "@/api/home";
  3. import { userInfoApi } from "@/api/login";
  4. import { UserInfoRep, cleanBounsApi, getUserTransferApi } from "@/api/user";
  5. import {
  6. BalanceContent,
  7. BonusContent,
  8. FreeContent,
  9. ReplayContent,
  10. } from "@/components/ModalPopup/WalletDescribeModal";
  11. import TipsModal, { ModalProps } from "@/components/TipsModal";
  12. import Vip from "@/components/Vip";
  13. import { HeaderImageMap } from "@/enums";
  14. import useGame from "@/hooks/useGame";
  15. import { Link, useRouter } from "@/i18n/routing";
  16. import { usePollingStore } from "@/stores/usePollingStore";
  17. import { useVipStore } from "@/stores/useVipStore";
  18. import { useWalletStore } from "@/stores/useWalletStore";
  19. import { WalletEnum } from "@/types";
  20. import { vipImages } from "@/utils/constant";
  21. import { copyText, percentage } from "@/utils/methods";
  22. import { useRequest } from "ahooks";
  23. import { Badge, Button, Mask, ProgressBar, Toast } from "antd-mobile";
  24. import clsx from "clsx";
  25. import { useTranslations } from "next-intl";
  26. import Image from "next/image";
  27. import { Fragment, useEffect, useMemo, useRef, useState } from "react";
  28. import { shallow } from "zustand/shallow";
  29. import ChangeAvatar from "./component/ChangeAvatar";
  30. type Props = {
  31. userInfo: UserInfoRep;
  32. };
  33. const VipCard = () => {
  34. const t = useTranslations("ProfilePage");
  35. // const vip_score_exp = useVipStore((state) => state.vipData!.vip_score_exp);
  36. // const vip_level = useVipStore((state) => state.vipData!.vip_level);
  37. // const vip_next_level = useVipStore((state) => state.vipData!.vip_next_level);
  38. // const vip_exp = useVipStore((state) => state.vipData!.vip_exp);
  39. const userVip = useVipStore((state) => {
  40. return {
  41. vip_score_exp: state.vipData!.vip_score_exp,
  42. vip_level: state.vipData!.vip_level,
  43. vip_next_level: state.vipData!.vip_next_level,
  44. vip_exp: state.vipData!.vip_exp,
  45. };
  46. }, shallow);
  47. const router = useRouter();
  48. // Vip 图标
  49. const vipIconElement = vipImages.map((item, index) => {
  50. if (item.leve === userVip.vip_level) {
  51. return (
  52. <Fragment key={index}>
  53. <Image src={item.src} alt={"vip"} height={110} width={100} />
  54. <span className={"icon-level"} style={{ color: item.color }}>
  55. {item.leve}
  56. </span>
  57. </Fragment>
  58. );
  59. }
  60. });
  61. // const vipIconElement = vipImages.map((item, index) => {
  62. // if (item.leve === userVip?.vip_level) {
  63. // return (
  64. // <Fragment key={index}>
  65. // <Image src={item.src} className="block" alt={"vip"} height={110} width={100} />
  66. // <span className={"icon-level"} style={{ color: item.color }}>
  67. // {item.leve}
  68. // </span>
  69. // </Fragment>
  70. // );
  71. // }
  72. // });
  73. // if (!userVip) return null;
  74. return (
  75. <div className={"vip-card"}>
  76. {/* <div className={"vip-card__icon"}>{vipIconElement}</div> */}
  77. <div className={"vip-card-process"}>
  78. {/*<div className={"process-top"}>{userVip.vip_exp}xp</div>*/}
  79. <div className="relative mr-[.1rem] flex-1 px-[.3rem]">
  80. <ProgressBar
  81. percent={percentage(userVip.vip_exp, userVip.vip_score_exp)}
  82. style={{
  83. "--fill-color": "#11de68",
  84. "--track-color": "#2b363f",
  85. "--track-width": ".12rem",
  86. }}
  87. />
  88. <div className={"process-bottom text-[#e581ff]"}>
  89. <span className="bg-[#0abd71]">VIP{userVip?.vip_level}</span>
  90. <div className={"process-bottom-desc"}>
  91. {userVip.vip_exp}/{userVip.vip_score_exp}
  92. </div>
  93. <span className="bg-[#eac61f]">
  94. VIP
  95. {userVip.vip_next_level}
  96. </span>
  97. </div>
  98. </div>
  99. <div className="vip-card-text" onClick={() => router.push("/vip")}>
  100. <span className="underline">CLUBE VIP</span>
  101. <i className="iconfont icon-xiangzuo1 block rotate-[180deg]"></i>
  102. </div>
  103. </div>
  104. </div>
  105. );
  106. };
  107. const WalletCard = () => {
  108. const userMoney = useWalletStore((state) => {
  109. return {
  110. score: state.wallet.score,
  111. point: state.wallet.point,
  112. free_score: state.wallet.free_score,
  113. free_transfer_min: state.wallet.free_transfer_min,
  114. lose_transfer_min: state.wallet.lose_transfer_min,
  115. is_point_transfer: state.wallet.is_point_transfer,
  116. is_free_transfer: state.wallet.is_free_transfer,
  117. is_lose_transfer: state.wallet.is_lose_transfer,
  118. lose_score: state.wallet.lose_score,
  119. };
  120. }, shallow);
  121. const t = useTranslations("ProfilePage");
  122. const tcdoe = useTranslations();
  123. const tipsRef = useRef<ModalProps>(null);
  124. const [tipsStatus, setTipsStatus] = useState<keyof typeof WalletEnum>("Bonus");
  125. const modalHandler = (key: keyof typeof WalletEnum) => {
  126. setTipsStatus(key);
  127. tipsRef.current?.onOpen();
  128. };
  129. // 未完成游戏
  130. const gameModelRef = useRef<ModalProps>(null);
  131. const game = useRef<(GameListRep & { mode: GameRequest["mode"] }) | null>(null);
  132. // 彩金、免费币、重玩币提现到钱包操作
  133. const handleAcquire = async (wallet_type: number, transfer: boolean) => {
  134. if (!transfer) return;
  135. // 先判断是否有未完成的游戏
  136. const { data }: any = await userInfoApi();
  137. // 如果有未完成游戏 彩金游戏-2、免费游戏-3、重玩游戏-4
  138. if (wallet_type === 2 && data.play_list && data.play_list.length > 0) {
  139. game.current = data.play_list[0];
  140. game.current!.mode = 1;
  141. gameModelRef.current?.onOpen();
  142. return;
  143. }
  144. if (wallet_type === 3 && data.free_game_list && data.free_game_list.length > 0) {
  145. game.current = data.free_game_list[0];
  146. gameModelRef.current?.onOpen();
  147. game.current!.mode = 2;
  148. return;
  149. }
  150. if (wallet_type === 4 && data.lose_game_list && data.lose_game_list.length > 0) {
  151. game.current = data.lose_game_list[0];
  152. game.current!.mode = 3;
  153. gameModelRef.current?.onOpen();
  154. return;
  155. }
  156. getUserTransferApi({ wallet_type })
  157. .then((res) => {
  158. if (res.code === 200) {
  159. Toast.show(tcdoe("code.200"));
  160. setTimeout(() => {
  161. tipsRef.current?.onClose();
  162. }, 1000);
  163. }
  164. })
  165. .catch((error) => {
  166. Toast.show(tcdoe(`code.${error.data.code}`));
  167. });
  168. };
  169. const { getGameUrl } = useGame();
  170. const goGame = () => {
  171. const current = game.current;
  172. getGameUrl(current!, { id: current?.id + "", mode: game.current?.mode! });
  173. tipsRef.current?.onClose();
  174. gameModelRef.current?.onClose();
  175. };
  176. const walletCfg = useMemo(() => {
  177. return [
  178. {
  179. title: t("balance"),
  180. icon: "icon-qianbao3",
  181. onClick: () => modalHandler(WalletEnum.Balance),
  182. value: userMoney.score || "0.0",
  183. key: "balance",
  184. dot: userMoney.is_point_transfer ? Badge.dot : null,
  185. },
  186. {
  187. title: t("bonus"),
  188. icon: "icon-meiyuanzhanghuyue",
  189. onClick: () => modalHandler(WalletEnum.Bonus),
  190. value: userMoney.point || "0.0",
  191. key: "bonus",
  192. dot: userMoney.is_point_transfer ? Badge.dot : null,
  193. },
  194. {
  195. title: t("free"),
  196. icon: "icon-Free-Tag",
  197. onClick: () => modalHandler(WalletEnum.Free),
  198. value: userMoney.free_score || "0.0",
  199. key: "free",
  200. iconStyle: { fontSize: ".22rem" },
  201. dot:
  202. userMoney.is_free_transfer &&
  203. userMoney.free_score >= (userMoney?.free_transfer_min || 0)
  204. ? Badge.dot
  205. : null,
  206. },
  207. {
  208. title: t("replay"),
  209. icon: "icon-meiyuan2",
  210. onClick: () => modalHandler(WalletEnum.Replay),
  211. value: userMoney.lose_score || "0.0",
  212. key: "replay",
  213. dot:
  214. userMoney.is_lose_transfer &&
  215. userMoney.lose_score >= (userMoney?.lose_transfer_min || 0)
  216. ? Badge.dot
  217. : null,
  218. },
  219. ];
  220. }, [userMoney]);
  221. return (
  222. <>
  223. <TipsModal
  224. className="walletModal"
  225. ref={tipsRef}
  226. title={
  227. <div className={"flex items-center text-[#11de68]"}>
  228. <i
  229. className={"iconfont icon-liwuhuodong mr-[0.0694rem] text-[0.2778rem]"}
  230. ></i>
  231. {t("modalTitle")}
  232. </div>
  233. }
  234. >
  235. {/*/!*现金*!/*/}
  236. {tipsStatus === WalletEnum.Balance ? <BalanceContent /> : null}
  237. {/*/!* 彩金*!/*/}
  238. {tipsStatus === WalletEnum.Bonus ? (
  239. <BonusContent handleAcquire={handleAcquire} />
  240. ) : null}
  241. {/*/!* 免费币 *!/*/}
  242. {tipsStatus === WalletEnum.Free ? (
  243. <FreeContent handleAcquire={handleAcquire} />
  244. ) : null}
  245. {/*/!* 重玩币 *!/*/}
  246. {tipsStatus === WalletEnum.Replay ? (
  247. <ReplayContent handleAcquire={handleAcquire} />
  248. ) : null}
  249. </TipsModal>
  250. {/* 提现拦截 */}
  251. <TipsModal title={"Tips"} ref={gameModelRef}>
  252. <p className={"text-left text-[0.12rem] font-medium text-[#666]"}>
  253. Existem jogos de bônus pendentes que não podem iniciar a retirada.
  254. </p>
  255. <div className={"mt-[0.0694rem] flex justify-center"}>
  256. <Button
  257. color={"primary"}
  258. className={"mx-auto"}
  259. style={{
  260. "--background-color": "var(--primary-color)",
  261. "--border-color": "var(--primary-color)",
  262. }}
  263. onClick={goGame}
  264. >
  265. para jogos
  266. </Button>
  267. </div>
  268. </TipsModal>
  269. <div className="coin">
  270. <div className={"coin_right_wallet"}>
  271. {walletCfg.map((item, index) => {
  272. return (
  273. <div
  274. key={item.key}
  275. className={"wallet_right_content"}
  276. onClick={item.onClick}
  277. >
  278. <Badge
  279. content={item.dot}
  280. style={{
  281. right: "4px",
  282. top: "50%",
  283. width: "6px",
  284. height: "6px",
  285. minWidth: "6px",
  286. }}
  287. >
  288. <div className="wallet-right-icon">
  289. <span
  290. className={clsx("coin_left__icon iconfont", item.icon)}
  291. style={{ ...(item.iconStyle || {}) }}
  292. ></span>
  293. </div>
  294. </Badge>
  295. <section>
  296. <div className={"wallet_header"}>
  297. {item.title}
  298. <div className="wallet-question">?</div>
  299. </div>
  300. <div className="num">
  301. <span className="uppercase">R$</span>
  302. <span>{item.value}</span>
  303. </div>
  304. </section>
  305. </div>
  306. );
  307. })}
  308. </div>
  309. </div>
  310. </>
  311. );
  312. };
  313. const NoBounsWarn = ({ visible, onClose, onConfirm }: any) => {
  314. const doClose = () => {
  315. if (typeof onClose === "function") onClose();
  316. };
  317. const doConfirm = () => {
  318. if (typeof onConfirm === "function") onConfirm();
  319. };
  320. return (
  321. <Mask visible={visible} onMaskClick={doClose}>
  322. <div className="absolute left-[50%] top-[40%] w-[80%] translate-x-[-50%]">
  323. <div className="relative rounded-[.1rem] bg-[#1f2830] px-[.15rem] pb-[.15rem] pt-[0px]">
  324. <div className="h-[.5rem] text-center">
  325. <img
  326. src="/warn_top.webp"
  327. alt=""
  328. className="relative -top-[.3rem] inline-block w-[.9rem]"
  329. />
  330. </div>
  331. <div className="text-center text-[.12rem]">
  332. A demanda atual de fluxo de retirada de bônus é excessiva,Se esvaziar o
  333. bônus e retirar a demanda de água corrente?
  334. </div>
  335. <div className="mt-[.2rem] flex items-center justify-between px-[.1rem]">
  336. <button
  337. onClick={doConfirm}
  338. className="mr-[.1rem] h-[.35rem] flex-1 rounded-[60px] bg-[#11de68] text-[.14rem] font-bold text-[#12171a]"
  339. >
  340. A certeza
  341. </button>
  342. <button
  343. onClick={doClose}
  344. className="h-[.35rem] flex-1 rounded-[60px] bg-[#ebc71f] text-[.14rem] font-bold text-[#12171a]"
  345. >
  346. Cancelar
  347. </button>
  348. </div>
  349. <i
  350. className="iconfont icon-guanbi absolute right-[.1rem] top-[.1rem]"
  351. onClick={doClose}
  352. ></i>
  353. </div>
  354. </div>
  355. </Mask>
  356. );
  357. };
  358. export const ProfileHeader = () => {
  359. const t = useTranslations("ProfilePage");
  360. const userMoney = useWalletStore((state) => {
  361. return {
  362. target_point_rollover: state.wallet?.target_point_rollover,
  363. score: state.wallet?.score,
  364. point: state.wallet?.point,
  365. no_bonus_config: state.wallet?.no_bonus_config,
  366. current_score_rollover: state.wallet?.current_score_rollover,
  367. target_score_rollover: state.wallet?.target_score_rollover,
  368. };
  369. }, shallow);
  370. const refresh = usePollingStore((state) => state.refresh);
  371. const tc = useTranslations();
  372. const vipInfo = useVipStore((state) => state.vipData);
  373. // const { wallet, setWallet } = useWalletStore((state) => ({
  374. // wallet: state.wallet,
  375. // setWallet: state.setWallet,
  376. // }));
  377. const router = useRouter();
  378. const [isShowNoBounsWarn, setIsShowNoBounsWarn] = useState(false);
  379. const [isShowAvatar, setIsShowAvatar] = useState(false);
  380. const [isShowed, setIsShowed] = useState(false);
  381. const { data: userInfo, run: refreshUserInfo } = useRequest<any, any>(userInfoApi, {
  382. pollingErrorRetryCount: 1,
  383. });
  384. // const userInfo = useMemo(() => {
  385. // return data?.data;
  386. // }, [data]);
  387. useEffect(() => {
  388. const curMul =
  389. userMoney.target_point_rollover / ((userMoney.score || 0) + (userMoney.point || 0));
  390. const percent = percentage(
  391. userMoney.current_score_rollover,
  392. userMoney.target_score_rollover
  393. );
  394. const config = userMoney.no_bonus_config;
  395. if (curMul >= (config || 0) && !isShowed && percent < 100) {
  396. setTimeout(() => {
  397. setIsShowNoBounsWarn(true);
  398. }, 1000);
  399. setIsShowed(true);
  400. }
  401. //todo 修改数据回显
  402. }, [isShowed]);
  403. const handler = () => {
  404. if (!!userMoney.score) {
  405. router.push("/deposit?target=2");
  406. } else {
  407. Toast.show("no money");
  408. }
  409. };
  410. const doConfirm = async () => {
  411. Toast.show({
  412. icon: "loading",
  413. maskClickable: false,
  414. });
  415. setIsShowNoBounsWarn(false);
  416. const res = await cleanBounsApi(1);
  417. if (res?.code && [6001, 6002].includes(res?.data?.code)) {
  418. const str = t(`bouns${res?.data?.code}`);
  419. Toast.show({
  420. content: str,
  421. icon: "fail",
  422. });
  423. }
  424. Toast.show({
  425. content: t("success"),
  426. icon: "success",
  427. });
  428. // const walletRes = await getUserMoneyApi();
  429. // setWallet(walletRes?.data);
  430. refresh && refresh();
  431. };
  432. const doCopyUsreId = (evt: any) => {
  433. (evt as any).stopPropagation();
  434. copyText(`${userInfo.data.user_phone}`);
  435. Toast.show({ icon: "success", content: tc("SummaryPage.copySuc"), maskClickable: false });
  436. };
  437. return (
  438. <>
  439. <div className={"userContent"}>
  440. <div className={"userInfo"}>
  441. <div onClick={() => setIsShowAvatar(true)}>
  442. <div className={"bgImg"}>
  443. <Image
  444. src={
  445. HeaderImageMap.get(userInfo?.data?.avatar)?.img ||
  446. "/img/avatar.webp"
  447. }
  448. className={
  449. "h-[100%] w-[100%] rounded-[50%] border-[2px] border-[#ccc]"
  450. }
  451. alt={"avatar"}
  452. width={120}
  453. height={120}
  454. />
  455. <Vip
  456. style={{
  457. position: "absolute",
  458. bottom: "0",
  459. }}
  460. level={vipInfo?.vip_level || 1}
  461. vipIconClassName="relative z-[3]"
  462. vipIconStyle={{ width: ".3rem" }}
  463. ></Vip>
  464. </div>
  465. <div>
  466. <span className="font-bold">
  467. {userInfo?.data?.nick_name || t("Conta")}
  468. </span>
  469. <div className="flex items-center">
  470. <span className="phone text-[#7b939a]">
  471. {userInfo?.data?.user_phone || ""}
  472. </span>
  473. <i
  474. className="iconfont icon-fuzhi1 text-[#7b939a]"
  475. onClick={doCopyUsreId}
  476. ></i>
  477. </div>
  478. </div>
  479. </div>
  480. {/* <Link
  481. className="goto iconfont icon-xiangzuo1 text-[#7b939a]"
  482. href={`/changePassword`}
  483. ></Link> */}
  484. </div>
  485. {/*vipcard*/}
  486. <VipCard />
  487. <WalletCard />
  488. </div>
  489. <div className="link">
  490. <Link href={"/deposit"} className={"btn"}>
  491. <i className="iconfont icon-meiyuanzhanghuyue mr-[.1rem]"></i>
  492. <span>{t("Depósito")}</span>
  493. </Link>
  494. <p className={"btn"} onClick={handler}>
  495. <i className="iconfont icon-zhuishou-meiyuan-shi mr-[.1rem]"></i>
  496. <span>{t("Sacar")}</span>
  497. </p>
  498. </div>
  499. <NoBounsWarn
  500. visible={isShowNoBounsWarn} // 控制是否显示遮罩层,true 显示,false 不显示
  501. onClose={() => setIsShowNoBounsWarn(false)}
  502. onConfirm={doConfirm}
  503. ></NoBounsWarn>
  504. <ChangeAvatar
  505. visible={isShowAvatar}
  506. useInfo={userInfo?.data}
  507. onClose={(needRefresh?: boolean) => {
  508. if (needRefresh) refreshUserInfo();
  509. setIsShowAvatar(false);
  510. }}
  511. ></ChangeAvatar>
  512. </>
  513. );
  514. };